//
//  PPNetworkManager.h
//  pickpic
//
//  Created by Jinxiao on 8/28/16.
//  Copyright © 2016 MicroDream. All rights reserved.
//

#import <AFNetworking/AFNetworking.h>
@interface PPNetworkManager : AFHTTPSessionManager
//跟afnetworking的网络监控是对应的
typedef NS_ENUM (NSInteger, PPNetStatus) {
    PPNetStatusUnKnown          = -1,
    PPNetStatusNotReachable     = 0,
    PPNetStatusMobile           = 1,
    PPNetStatusWIFI             = 2,
};
@property (nonatomic, assign, readonly) PPNetStatus networkStatus;

+ (instancetype)sharedInstance;
- (NSURLSessionTask *)post:(NSString *)url
                    params:(NSDictionary *)params
                  callback:(void(^)(id data, NSError *error))callback;


- (NSURLSessionTask *)get:(NSString *)url
                    params:(NSDictionary *)params
                  callback:(void(^)(id data, NSError *error))callback;

+ (void)downLoadImageWithUrl:(NSString *)url callback:(void (^)(UIImage *downImage, NSError *error))callback;

- (void)checkNetworkStatusChangeBlock:(void (^)(PPNetStatus))netStatus;

- (NSURLSessionTask *)postCreateEbook:(NSString *)url
                               params:(NSDictionary *)params
                             progress:(void (^_Nullable)(NSProgress * _Nonnull))uploadProgress
                             callback:(void (^_Nullable)(id _Nullable data, NSError * _Nullable error))callback;

- (void)DELETEData:(NSString *)url
                      params:(NSDictionary *)params
                    callback:(void (^)(id data, NSError *error))callback ;

@end

// ----------------- 华丽的分割线 （错误处理类）-------
/**请求成功
 */
#define kVMRequestSuccess @"0"

/**请求成功，但是业务返回错误
 */
#define kVMRequestFail @"1"

/**请求失败，网络错误
 */
#define kVMRequestNetFailCode @"-1"
#define kVMRequestNetFailMeg @"网络出问题啦~"
/**参数错误
 */
#define kVMRequestParamsFail @"-2"

/**未知错误
 */
#define kVMRequestUnknowFail @"-3"


@interface PPError : NSObject

/**
 *kVMRequestSuccess = 0
 *kVMRequestFail = 1
 *kVMRequestNetFail = -1
 *kVMRequestParamsFail = -2
 *kVMRequestUnknowFail = -3
 */
@property (nonatomic, strong) NSString *errorCode;
@property (nonatomic, strong) NSString *errorReason;
@property (nonatomic, strong) NSDictionary *userInfo;


@property (nonatomic, copy) NSString   *errorMeg;

@end
